<HTML><HEAD><TITLE>define_error(+Message, -N)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Obsolete</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>define_error(+Message, -N)</H1>
Error number N is newly defined to give the message Message.


<DL>
<DT><EM>Message</EM></DT>
<DD>String.
</DD>
<DT><EM>N</EM></DT>
<DD>Variable.
</DD>
</DL>
<H3>This built-in predicate is obsolete!</H3>
<H2>Description</H2>
   This predicate is used to define new user error types.  Message is a
   string which is going to be printed when this error occurs (the string
   returned by error_id/2).  N is bound to the new error number.  The
   default error handler for the new error is error_handler/2.

<P>
   Note that the error numbers should not be hard-coded in subsequent calls
   to error/2 etc., as the error numbers are arranged at run time and may
   be changed between releases.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>define_error(+, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Message is not instantiated.
<DT><EM>(5) type error </EM>
<DD>Message is instantiated, but not to a string.
<DT><EM>(5) type error </EM>
<DD>N is instantiated.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      define_error("my first error message",N).  (gives N=340).
      define_error("my second error message",N). (gives N=341).

      [eclipse]: [user].
       :- define_error("1st arg should be number",N),
          setval(usererror, N).
       do(N,Res) :-(number(N) -&gt;
              Res is sqrt(N)
              ;
              getval(usererror, Err),
              error(Err, do(N,Res))).
       user compiled 232 bytes in 0.00 seconds
      yes.
      [eclipse]: do(4,2.0).
      yes.
      [eclipse]: do(four,2.0).
      1st arg should be number in do(four, 2.0)
Error:
      define_error(M,N).                    (Error 4).
      define_error(atom,N).                 (Error 5).
      define_error("incorrect module",340). (Error 5).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/event/set_event_handler-2.html">set_event_handler / 2</A>, <A HREF="../../kernel/event/error_id-2.html">error_id / 2</A>
</BODY></HTML>
